<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">菜单管理</h1>
</div>



<div class="wrapper-md"  >
<div class="panel panel-default">
  <div ng-controller="infoEditCtrl">
    <div class="row">
    
      <div class="col-sm-12" >
        <form name="form-contact" ng-submit="processForm()" class="form-horizontal">

            <div class="panel-heading">
              <span class="h4">

<button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>


              </span>
            </div>
            <div class="panel-body">
            

       
 <div class="panel-heading">
              <span class="h4" style="color: blue;">菜单简介信息</span>
            </div>




<div class="form-group">
    <label class="col-sm-1 control-label">父菜单</label>
    <div class="col-sm-5">

   <select class="form-control " ng-model="contact.FatherId"  required >
                     <option ng-repeat="x in fathers" value="{{x.key}}">{{x.value}}</option>
                  </select>



    </div>

  
 <label  class="col-sm-1 control-label">层级</label>
    <div class="col-sm-5">
      <input type="number" class="form-control"  ng-model="contact.MenuLayer" required >
    </div>
  </div>

  <div class="line line-dashed b-b line-lg pull-in"></div>




<div class="form-group">
    <label class="col-sm-1 control-label">菜单名称</label>
    <div class="col-sm-5">
 <input type="text" class="form-control" placeholder="菜单名称" ng-model="contact.MenuName" required >
    </div>

    <label  class="col-sm-1 control-label">菜单全称</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" placeholder="菜单全称" ng-model="contact.MenuLongName" required >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


<div class="form-group">
    <label class="col-sm-1 control-label">地址</label>
    <div class="col-sm-5">
 <input type="text" class="form-control" ng-model="contact.MenuUrl"  >
    </div>
 <label  class="col-sm-1 control-label">顺序</label>
    <div class="col-sm-5">
      <input type="number" class="form-control"  ng-model="contact.MenuDisplayOrder" required >
    </div>
  
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>





              <div class="form-group">
                 <label class="col-sm-1 control-label">备注</label>  
               <div class="col-sm-10">
                   <textarea class="form-control" ng-model="contact.MenuRemark" rows="6" placeholder="备注">{{contact.MenuRemark}}</textarea>
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>




  
    <div class="form-group">
                 <label class="col-sm-1 control-label">小图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.MenuSmallIcon" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

      <div class="form-group">
                 <label class="col-sm-1 control-label">中图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.MenuMediumIcon" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


      <div class="form-group">
                 <label class="col-sm-1 control-label">大图标</label>  
               <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="" ng-model="contact.MenuLargeIcon" >
               </div>
                </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>

            </div>

        

                 <div class="panel-body">

    
           
 <div class="panel-heading">
              <span class="h4" style="color: blue;">配置信息</span>
            </div>



    <div class="form-group">
    <label class="col-sm-1 control-label">前台显示</label>
    <div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
              <input type="checkbox" ng-model="menuIsDisplay"  checked>
              <i></i>
            </label>
    </div>


  


  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>





  <!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="contact.MenuUuid"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'"  >
    <!--隐藏字段-->

            </div>


            <footer class="panel-footer text-right bg-light lter">
              <button type="submit" class="btn btn-success">提交</button>
            </footer>
          </div>
        </form>
      </div>
    </div>
   
</div>
</div>




</div>


<!--angularjs-->
<script type="text/javascript">




//单条删除
  function goDelete(id){
      top.layer.confirm('您确定删除吗', function(index){
              var postInfoUrl = API_URL+"menu_info";

          var infoUrl = API_URL+"menu_info?query=delflag:0,Id:"+id;

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];

         formData.Delflag = "1";
   $.ajax({
      url : postInfoUrl+'/'+id,
      type : 'put',
      data: JSON.stringify(formData),
      cache : false,
      success : function(data) {
        top.layer.msg('删除成功');

     
      $("#myTable").DataTable().ajax.reload().draw();
      }
    });



 top.layer.close(index);
      });
  }


  'use strict';
app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {

  $scope.menuIsDisplay = true;

  var fatherDatas = [{key : "0", value : "顶级菜单"}];

  var getInfoUrl = API_URL+"menu_info?query=delflag:0,FatherId:0"    

  var fatherDBs=  MY_ASYNC_AJAX(getInfoUrl);

  for(var i=0;i<fatherDBs.length;i++){
    var menuDataId = fatherDBs[i].Id+"";
    var menuDataName = fatherDBs[i].MenuName+"";
    var menuData = {key : menuDataId, value :  menuDataName};
    fatherDatas.push(menuData);
  }
 $scope.fathers = fatherDatas;

//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.back();
    };
//返回按钮：结束
    var infoId = $stateParams.infoId;
    console.log('获取路由参数infoId：'+infoId);


 //如果infoId不为空，查询详情：开始
  if(''!=infoId){
      var getInfoUrl = API_URL+"menu_info?query=delflag:0,Id:"+infoId;    

    $http.get(getInfoUrl).success(function (response) {
         var obj = response[0];
           obj.MenuDisplayOrder = Number(obj.MenuDisplayOrder);
           obj.MenuLayer  =  Number(obj.MenuLayer);
             if("0" == obj.MenuIsDisplay){
          $scope.menuIsDisplay = false;
         }

           $scope.contact = obj;

           console.log(JSON.stringify($scope.contact));

      });
  }
//如果infoId不为空，查询详情：结束






  //表单提交开始
$scope.processForm= function (){
 
  //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"menu_info";
var formData =  $scope.contact;

  //1.参数处理
    formData.AddTime = getNowDBFormatDate();
    formData.UpdateTime = getNowDBFormatDate();
    formData.AdderId = 1;
    formData.AdderName = '1';
    formData.UpdaterId = 1;
    formData.UpdaterName = '1';
    formData.ChannelUuid='';
    formData.MenuDisplayOrder=formData.MenuDisplayOrder + '';

    formData.FatherId = Number(formData.FatherId);
    formData.MenuIsDisplay = '1';

    if(false == $scope.menuIsDisplay){
          formData.MenuIsDisplay = '0';
         }
 
    console.log(JSON.stringify(formData));
  if("undefined"!=typeof(formData.Id)){

          $.ajax({  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                  top.layer.msg('保存成功', {icon: 6});
                  //2.成功跳转页面
                  $state.go('app.menuInfo.menuInfo');
                  }  
             }); 
              }else{

           $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.menuInfo.menuInfo');
                  }  
             }); 

  }
}

});
</script>
<!--angularjs-->










